<template>
	<view class="pos-real">
		<u-navbar title="优惠券列表" :background="{ backgroundColor: '#FF9F43' }" :borderBottom="false" titleColor="#fff"
			backIconColor="#fff"></u-navbar>

		<view v-for="(items,indexs) in disCountList" :key="indexs">
			<view v-for="(item,index) in items.discountCoupon" :key="index">
				<view v-if="item.num>0" class="mg-base" style="background-color: white;border-radius: 14rpx;">
					<view class="uni-flex justify-between" style="padding-top: 10rpx;">
						<view style="margin-left: 20rpx;">
							<image style="width: 152rpx;height: 128rpx;"
								src="https://7463-tcb-zoumbaexjdidjmj2ff212-5d3479-1303238310.tcb.qcloud.la/hycz-youhuiquanimg2.png">
							</image>
						</view>
						<view>
							<view style="font-size: 32rpx;color: #FE6A46;font-weight: 600;">
								{{(item.money/100).toFixed(2)}}元抵扣券X{{item.num}}张
							</view>
							<view class="uni-flex">
								<text style="font-size: 20rpx;color: #666666;">截至使用时间:</text>
								<view style="font-size: 20rpx;color: #666666;">
									<uni-dateformat :date="items.endTime" format="yyyy/MM/dd">
									</uni-dateformat>
								</view>
							</view>
							<view @click="getStoreList(items.storeIds)" class="uni-flex align-center"
								style="background-color: #FFFBF6;">
								<view class="storename" style="font-size: 24rpx;">可用门店：{{items.storeId[0].name}}</view>

								<image style="width: 18rpx;height: 12rpx;"
									src="https://7463-tcb-zoumbaexjdidjmj2ff212-5d3479-1303238310.tcb.qcloud.la/hycz-xiajiantou3.png">
								</image>
							</view>
						</view>
						<view>
							<image style="width: 120rpx;height: 120rpx;"
								src="https://7463-tcb-zoumbaexjdidjmj2ff212-5d3479-1303238310.tcb.qcloud.la/hycz-daishiyong2.png">
							</image>
						</view>
					</view>
					<view class="uni-flex justify-between align-center">
						<view
							style="width: 20rpx;height: 20rpx;background-color:rgb(245, 245, 245);border-radius: 100rpx;">
						</view>
						<u-line color="rgb(31,34,63)" border-style="dashed" />
						<view
							style="width: 20rpx;height: 20rpx;background-color: rgb(245, 245, 245);border-radius: 100rpx;">
						</view>
					</view>

					<view
						style="word-wrap: break-word;font-size: 20rpx;color: #999999;margin-left: 20rpx;margin-right: 20rpx;">
						<u-read-more  :toggle="true" text-indent="0" color="#999999" :shadow-style="shadowStyle"
							show-height="40"  close-text=" " open-text="收起">
								<rich-text style="font-size: 20rpx;color: #999999;"
									:nodes="item.desc" ></rich-text>
						</u-read-more>
					</view>
				</view>

			</view>
		</view>
		<u-popup v-model="storeListShow" mode="bottom" length="50%" border-radius="14" @close="storeListShowclose()">
			<view class="mg-base">
				<view>
					<view class="uni-flex justify-between align-center">
						<view><text style="font-size: 32rpx; font-weight: 600;">可用门店{{(storeListPopup).length}}家</text>
						</view>
						<view>
							<image style="width: 30rpx;height: 30rpx;"
								src="https://7463-tcb-rxeszamj94676b-6d6j813d8fcf0-1303238310.tcb.qcloud.la/static/img/删除2@2x.png">
							</image>
						</view>
					</view>
				</view>
				<view>
					<view v-for="(item,index) in storeListPopup" :key="index">
						<image
							src="https://7463-tcb-rxeszamj94676b-6d6j813d8fcf0-1303238310.tcb.qcloud.la/static/img/czmx-mendian.png"
							mode="scaleToFill" style="width: 100%; height: 66rpx;position: absolute;"></image>
						<view style="position: relative;margin-top: 20rpx;;margin-left: 80rpx;padding-top: 10rpx;">
							<text style="font-size: 28rpx">{{item.name}}</text>
						</view>
					</view>
				</view>
			</view>
		</u-popup>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	import {
		getUserInfo,
		getUserPackageSearch,
		getPackageProperty
	} from "@/api/platform/user.js";
	import {
		genPackageOrder,
		genPayInfo,
		updatePakcageState
	} from "@/api/platform/order.js";
	const db = uniCloud.database()
	export default {
		data() {
			return {

				selectedStoreIdx: 0,
				storeList: null,
				activeItemStyle: {
					backgroundColor: '#FF7D66',
					border: '2px solid #fff',
					borderRadius: '40rpx'
				},
				topUpDetail: [],
				consumeDetail: [],
				packageAccount: {
					amount: 0,
					disCount: 0
				},
				storeListShow: false,
				storeListPopup: [],
				packageId: '',
				disCountList: [],
				storeId: '',
				shadowStyle: {
					backgroundImage: "none",
					paddingTop: "0",
					marginTop: "-30rpx",
					display: "flex",
					justifyContent: 'flex-end'

				}
			}
		},
		computed: {
			...mapState(["updateUserInfo", "userInfo"]),
		},
		onLoad(e) {
			if (e.storeId) {
				this.storeId = e.storeId;
				console.log(e.packageId)
			}
			uni.showLoading({
				mask: true
			})
			this.getData()
			uni.hideLoading()
		},
		async onReady() {
			uni.showLoading({
				mask: true
			})
			await this.getData()
			uni.hideLoading()
		},
		async onPullDownRefresh() {
			await this.getData();
			uni.stopPullDownRefresh();
		},
		methods: {
			parseLoaded(index) {
				// this.$refs.uReadMore+index;
				// var a = 'uReadMoreindex';
				console.log(this.$refs)
			},
			async loadDisCount() {
				const dbCmd = db.command
				const $ = dbCmd.aggregate
				var where = {
					uid: this.userInfo._id,
					type: 1,
					delFlag: 0
				}
				if (this.storeId) {
					where.storeIds = dbCmd.in([this.storeId])
				}
				db.collection('t3ds-package-user,t3ds-store').where(where).get().then(res => {
					this.disCountList = res.result.data
					console.log(this.disCountList)
				})
			},
			getStoreList(storeIdx) {
				console.log("storeIdx", storeIdx)
				const dbCmd = db.command
				const $ = dbCmd.aggregate
				db.collection('t3ds-store').where({
					_id: dbCmd.in(storeIdx)
				}).field("name").get().then(res => {
					this.storeListPopup = res.result.data;
					this.storeListShow = true
					//console.log("storeList",res)
				})
				// console.log(storeIdx)
			},
			async getData() {
				this.loadDisCount()
			},
			onDisCountItemDesc(item) {
				this.$refs.uToast.show({
					title: item.desc,
					type: 'primary'
				})
			},
			storeListShowclose() {},
		}
	}
</script>

<style>
	page {
		background-color: #F5F5F5;
	}
</style>

<style lang="scss" scoped>
	.storename {
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 1;
		overflow: hidden;
	}

	.u-tabs {
		background: #EBEBEB !important;
		height: 100rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		padding: 0 30rpx;
		border-radius: 50rpx;
	}

	.content {
		margin-top: 560rpx;
		padding-bottom: 60rpx;

		.content-money {
			height: 100%;
			position: relative;
			z-index: 9;
		}

		.content-item-1 {
			width: 690rpx;
			height: 170rpx;
			margin: 0 30rpx;
		}

		.content-item-2 {
			width: 330rpx;
			height: 130rpx;
		}

		.content-operate {
			background: #FFFFFF;
			border-radius: 24rpx;
			margin: 60rpx 30rpx 0 30rpx;
			padding: 0 30rpx;

			.content-operate-item:not(:last-child) {
				border-bottom: 1px solid #EAEAEA;
				;
			}
		}

		.content-btn {
			margin: 88rpx 30rpx 0 30rpx;

			.content-btn-0 {
				width: 330rpx;
				height: 88rpx;
				border-radius: 50rpx;
				font-size: 30rpx;
				color: white;
			}

			.content-btn-1 {
				background-color: #CFCFCF;
			}

			.content-btn-2 {
				background: #FF5673;
			}
		}

		.content-explain {
			margin: 60rpx 30rpx 0 30rpx;
			background: #E9E9E9;
			border-radius: 24rpx;
			padding: 30rpx;

			.content-explain-icon {
				width: 32rpx;
				height: 32rpx;
				filter: grayscale(1);
			}

			.content-explain-title {
				font-size: 30rpx;
				color: #5A5A5C;
			}
		}
	}
</style>